package com.foreknow.elm.dao.impl;

import com.foreknow.elm.dao.FoodDao;
import com.foreknow.elm.po.Business;
import com.foreknow.elm.po.Food;
import com.foreknow.elm.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author shkstart
 * @create 2021-08-26 15:55
 */
public class FoodDaoImpl  implements FoodDao {
    private Connection con = null;
    private PreparedStatement pst = null;
    private ResultSet rs = null;
    /**
     * 根据商家编号查询所属食品信息
     * @param businessId
     * @returnfood数组
     */
    @Override
    public List<Food> listFoodByBusinessId(int businessId) throws SQLException {
        List<Food> foods=new ArrayList<Food>();
        String sql = "select * from food where businessId=? order by foodId";
        //获取连接
         con = DBUtil.getConnection();
         pst=con.prepareStatement(sql);
        pst.setInt(1,businessId);
        rs= pst.executeQuery();
        while (rs.next()){
            Food food = new Food();
            food.setFoodId(rs.getInt("foodId"));
            food.setFoodName(rs.getString("foodName"));
            food.setFoodExplain(rs.getString("foodExplain"));
            food.setFoodImg(rs.getString("foodImg"));
            food.setFoodPrice(rs.getDouble("foodPrice"));
            food.setBusinessId(rs.getInt("businessId"));
            food.setRemarks(rs.getString("remarks"));
            foods.add(food);
        }
        return foods;
    }
}
